<%@page import="helpers.CkeditorConfigHelper"%>
<%@page import="java.util.TreeMap"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="helpers.DateHelper"%>
<%@page import="models.NewsModel"%>
<%@page import="java.util.ArrayList"%>
<%@page import="helpers.UrlHelper"%>
<%@page import="models.SiteConfigModel"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://ckeditor.com" prefix="ckeditor" %>
<%
TreeMap check = (TreeMap) request.getAttribute("check");
SiteConfigModel siteConfig = (SiteConfigModel) request.getAttribute("config");
String image = "";//UrlHelper.getServerUrl(request) + "/blobstore-serve?blob-key=" + siteConfig.getLogo();
String name = (String) request.getAttribute("name");
NewsModel news = (NewsModel) request.getAttribute("news");
String form = (String) request.getAttribute("form");
String success = (String) request.getAttribute("success");
%>

<jsp:include page="/layouts/header.jsp">
    <jsp:param name="title" value="<%=siteConfig.getTitle()%>" />
    <jsp:param name="description" value="<%=siteConfig.getMetaDescription()%>" />
    <jsp:param name="keywords" value="<%=siteConfig.getMetaKeywords()%>" />
    <jsp:param name="ogsite_name" value="<%=siteConfig.getSiteName()%>" />
    <jsp:param name="ogtitle" value="<%=siteConfig.getTitle()%>" />
    <jsp:param name="ogurl" value="<%=UrlHelper.getServerUrl(request)%>" />
    <jsp:param name="ogimage" value="<%=image %>" />
    <jsp:param name="ogdescription" value="<%=siteConfig.getMetaDescription()%>" />
</jsp:include>
<script type="text/javascript" src="/js/home.js"></script>
			<div class="block-content">
				<!-- STATIC PAGE -->
				<div class="static-block">
					<% if (success != null) { %>
					<div class="msg-s"><%=success %></div>
					<% } %>
					<div class="form-user">
						<h2><%=form.equalsIgnoreCase("edit") ? "Update News" : "Submit News" %></h2>
						<form action="" method="post">
						<table width="100%" cellpadding="0" cellspacing="0">
							<tbody>
								<tr>
									<td width="30%" class="url">Url</td>
									<td>
										<% if (check.get("url") != null) { %>
											<div class="error"><%=check.get("url")%></div>
										<% } %>
										<input type="text" name="url" id="n_url" class="mediuminput" value="<%=news.getUrl() != null ? news.getUrl() : "" %>" >
									</td>
								</tr>
								<tr class="dotline">
									<td width="30%" class="published">Publish</td>
									<td>
										<% if (check.get("published") != null) { %>
											<div class="error"><%=check.get("published")%></div>
										<% } %>
										Yes <input class="input type" type="radio" value="true" style="width: auto;" name="published" <%=news.isPublished() == true ? "checked=\"checked\"" : "" %>>&nbsp;&nbsp;&nbsp;&nbsp;
										No <input class="input type" type="radio" value="false" style="width: auto;" name="published" <%=news.isPublished() == false ? "checked=\"checked\"" : "" %>>&nbsp;&nbsp;&nbsp;&nbsp;
									</td>
								</tr>
								<tr>
									<td width="30%" class="hotNews">Hot News</td>
									<td>
										<% if (check.get("hotNews") != null) { %>
											<div class="error"><%=check.get("hotNews")%></div>
										<% } %>
										Yes <input class="input type" type="radio" value="true" style="width: auto;" name="hotNews" <%=news.isHotNews() == true ? "checked=\"checked\"" : "" %>>&nbsp;&nbsp;&nbsp;&nbsp;
										No <input class="input type" type="radio" value="false" style="width: auto;" name="hotNews" <%=news.isHotNews() == false ? "checked=\"checked\"" : "" %>>&nbsp;&nbsp;&nbsp;&nbsp;
									</td>
								</tr>
								<tr>
									<td width="30%" class="title">Title news</td>
									<td>
										<% if (check.get("title") != null) { %>
											<div class="error"><%=check.get("title")%></div>
										<% } %>
										<input type="text" name="title" id="n_title" class="longinput" value="<%=news.getTitle() != null ? news.getTitle() : "" %>" >
									</td>
								</tr>
								<tr>
									<td width="30%" class="image">Image</td>
									<td>
										<% if (check.get("image") != null) { %>
											<div class="error"><%=check.get("image")%></div>
										<% } %>
										<input type="text" name="image" id="n_image" class="longinput" value="<%//=news.getImage() != null ? news.getImage() : "" %>" >
									</td>
								</tr>
								<tr>
									<td width="30%" class="description">Description</td>
									<td>
										<% if (check.get("description") != null) { %>
											<div class="error"><%=check.get("description")%></div>
										<% } %>
										<textarea id="n_description" class="longinput ckeditor" name="description"  rows="5" cols="80"><%=news.getDescription() != null ? news.getDescription() : "" %></textarea>
										<ckeditor:replaceAll className="ckeditor" basePath="/sources/ckeditor/" 
											config="<%=CkeditorConfigHelper.createConfig() %>"
										   events="<%=CkeditorConfigHelper.createEventHandlers() %>" />
									</td>
								</tr>
								<tr>
									<td width="30%" class="category">Category</td>
									<td>
										<% if (check.get("category") != null) { %>
											<div class="error"><%=check.get("category")%></div>
										<% } %>
										<input type="text" name="category" id="n_category" class="smallinput" value="<%=news.getCategory() != null ? news.getCategory() : "" %>" >
									</td>
								</tr>
								<tr>
									<td></td>
									<td>
										<button type="submit"><%=!form.equalsIgnoreCase("add") ? "Update" : "Submit" %></button>
									</td>
								</tr>
							</tbody>
						</table>
						</form>
					</div>
				</div>
				<!-- END STATIC PAGE -->
			</div>

<jsp:include page="/layouts/footer.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>	